{% extends 'generic/object_detail.html' %}
{% load helpers %}
{% load static %}

{% block extra_buttons %}
        {% if perms.virtualization.add_vminterface %}
            <a href="{% url 'virtualization:vminterface_add' %}?virtual_machine={{ object.pk }}&return_url={{ object.get_absolute_url }}" class="btn btn-primary">
                <span class="mdi mdi-plus-thick" aria-hidden="true"></span> Add Interfaces
            </a>
        {% endif %}
{% endblock extra_buttons %}

{% block nav_tabs %}
        <li role="presentation"{% if not active_tab %} class="active"{% endif %}>
            <a href="{{ object.get_absolute_url }}">Virtual Machine</a>
        </li>
        {% if perms.extras.view_configcontext %}
            <li role="presentation"{% if active_tab == 'config-context' %} class="active"{% endif %}>
                <a href="{% url 'virtualization:virtualmachine_configcontext' pk=object.pk %}">Config Context</a>
            </li>
        {% endif %}
        {% if perms.extras.view_objectchange %}
            <li role="presentation"{% if active_tab == 'changelog' %} class="active"{% endif %}>
                <a href="{% url 'virtualization:virtualmachine_changelog' pk=object.pk %}">Change Log</a>
            </li>
        {% endif %}
{% endblock nav_tabs %}

{% block content_left_page %}
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Virtual Machine</strong>
            </div>
            <table class="table table-hover panel-body attr-table">
                <tr>
                    <td>Name</td>
                    <td>{{ object }}</td>
                </tr>
                <tr>
                    <td>Status</td>
                    <td>
                        <span class="label" style="color: {{ object.status.color|fgcolor }}; background-color: #{{ object.status.color }}">{{ object.get_status_display }}</span>
                    </td>
                </tr>
                <tr>
                    <td>Role</td>
                    <td>
                        {% if object.role %}
                            <a href="{% url 'virtualization:virtualmachine_list' %}?role={{ object.role.slug }}">{{ object.role }}</a>
                        {% else %}
                            <span class="text-muted">None</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Platform</td>
                    <td>
                        {% if object.platform %}
                            <a href="{% url 'virtualization:virtualmachine_list' %}?platform={{ object.platform.slug }}">{{ object.platform }}</a>
                        {% else %}
                            <span class="text-muted">None</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Tenant</td>
                    <td>
                        {% if object.tenant %}
                            {% if object.tenant.group %}
                                <a href="{{ object.tenant.group.get_absolute_url }}">{{ object.tenant.group }}</a> /
                            {% endif %}
                            <a href="{{ object.tenant.get_absolute_url }}">{{ object.tenant }}</a>
                        {% else %}
                            <span class="text-muted">None</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Primary IPv4</td>
                    <td>
                        {% if object.primary_ip4 %}
                            <a href="{% url 'ipam:ipaddress' pk=object.primary_ip4.pk %}">{{ object.primary_ip4.address.ip }}</a>
                            {% if object.primary_ip4.nat_inside %}
                                <span>(NAT for {{ object.primary_ip4.nat_inside.address.ip }})</span>
                            {% elif object.primary_ip4.nat_outside %}
                                <span>(NAT: {{ object.primary_ip4.nat_outside.address.ip }})</span>
                            {% endif %}
                        {% else %}
                            <span class="text-muted">&mdash;</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Primary IPv6</td>
                    <td>
                        {% if object.primary_ip6 %}
                            <a href="{% url 'ipam:ipaddress' pk=object.primary_ip6.pk %}">{{ object.primary_ip6.address.ip }}</a>
                            {% if object.primary_ip6.nat_inside %}
                                <span>(NAT for {{ object.primary_ip6.nat_inside.address.ip }})</span>
                            {% elif object.primary_ip6.nat_outside %}
                                <span>(NAT: {{ object.primary_ip6.nat_outside.address.ip }})</span>
                            {% endif %}
                        {% else %}
                            <span class="text-muted">&mdash;</span>
                        {% endif %}
                    </td>
                </tr>
            </table>
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Comments</strong>
            </div>
            <div class="panel-body rendered-markdown">
                {% if object.comments %}
                    {{ object.comments|render_markdown }}
                {% else %}
                    <span class="text-muted">None</span>
                {% endif %}
            </div>
        </div>
{% endblock content_left_page %}

{% block content_right_page %}
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Cluster</strong>
            </div>
            <table class="table table-hover panel-body attr-table">
                <tr>
                    <td>Cluster</td>
                    <td>
                        {% if object.cluster.group %}
                            <a href="{{ object.cluster.group.get_absolute_url }}">{{ object.cluster.group }}</a> /
                        {% endif %}
                        <a href="{{ object.cluster.get_absolute_url }}">{{ object.cluster }}</a>
                    </td>
                </tr>
                <tr>
                    <td>Cluster Type</td>
                    <td>{{ object.cluster.type }}</td>
                </tr>
            </table>
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Resources</strong>
            </div>
            <table class="table table-hover panel-body attr-table">
                <tr>
                    <td><i class="mdi mdi-gauge"></i> Virtual CPUs</td>
                    <td>{{ object.vcpus|placeholder }}</td>
                </tr>
                <tr>
                    <td><i class="mdi mdi-chip"></i> Memory</td>
                    <td>
                        {% if object.memory %}
                            {{ object.memory }} MB
                        {% else %}
                            <span class="text-muted">&mdash;</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td><i class="mdi mdi-harddisk"></i> Disk Space</td>
                    <td>
                        {% if object.disk %}
                            {{ object.disk }} GB
                        {% else %}
                            <span class="text-muted">&mdash;</span>
                        {% endif %}
                    </td>
                </tr>
            </table>
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Services</strong>
            </div>
            {% if services %}
                <table class="table table-hover panel-body">
                    {% for service in services %}
                        {% include 'ipam/inc/service.html' %}
                    {% endfor %}
                </table>
            {% else %}
                <div class="panel-body text-muted">
                    None
                </div>
            {% endif %}
            {% if perms.ipam.add_service %}
                <div class="panel-footer text-right noprint">
                    <a href="{% url 'virtualization:virtualmachine_service_assign' virtualmachine=object.pk %}" class="btn btn-xs btn-primary">
                        <span class="mdi mdi-plus-thick" aria-hidden="true"></span> Assign service
                    </a>
                </div>
            {% endif %}
        </div>
{% endblock content_right_page %}

{% block content_full_width_page %}
        <form method="post">
            {% csrf_token %}
            <input type="hidden" name="virtual_machine" value="{{ object.pk }}" />
            <div class="panel panel-default">
                <div class="panel-heading">
                    <strong>Interfaces</strong>
                    <div class="pull-right noprint">
                        {% if request.user.is_authenticated %}
                            <button type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#VirtualMachineVMInterfaceTable_config" title="Configure table"><i class="mdi mdi-cog"></i> Configure</button>
                        {% endif %}
                    </div>
                    <div class="pull-right col-md-2 noprint">
                        <input class="form-control interface-filter" type="text" placeholder="Filter" title="Filter text (regular expressions supported)" style="height: 23px" />
                    </div>
                </div>
                {% include 'responsive_table.html' with table=vminterface_table %}
                {% if perms.virtualization.add_vminterface or perms.virtualization.delete_vminterface %}
                    <div class="panel-footer noprint">
                        {% if interfaces and perms.virtualization.change_vminterface %}
                            <button type="submit" name="_rename" formaction="{% url 'virtualization:vminterface_bulk_rename' %}?return_url={{ object.get_absolute_url }}" class="btn btn-warning btn-xs">
                                <span class="mdi mdi-pencil" aria-hidden="true"></span> Rename
                            </button>
                            <button type="submit" name="_edit" formaction="{% url 'virtualization:vminterface_bulk_edit' %}?return_url={{ object.get_absolute_url }}" class="btn btn-warning btn-xs">
                                <span class="mdi mdi-pencil" aria-hidden="true"></span> Edit
                            </button>
                        {% endif %}
                        {% if interfaces and perms.virtualization.delete_vminterface %}
                            <button type="submit" name="_delete" formaction="{% url 'virtualization:vminterface_bulk_delete' %}?return_url={{ object.get_absolute_url }}" class="btn btn-danger btn-xs">
                                <span class="mdi mdi-trash-can-outline" aria-hidden="true"></span> Delete
                            </button>
                        {% endif %}
                        {% if perms.virtualization.add_vminterface %}
                            <div class="pull-right">
                                <a href="{% url 'virtualization:vminterface_add' %}?virtual_machine={{ object.pk }}&return_url={{ object.get_absolute_url }}" class="btn btn-primary btn-xs">
                                    <span class="mdi mdi-plus-thick" aria-hidden="true"></span> Add interfaces
                                </a>
                            </div>
                            <div class="clearfix"></div>
                        {% endif %}
                     </div>
                {% endif %}
            </div>
        </form>
        {% table_config_form vminterface_table %}
{% endblock content_full_width_page %}

{% block javascript %}
    <script src="{% static 'js/interface_filtering.js' %}?v{{ settings.VERSION }}"></script>
    <script src="{% static 'js/tableconfig.js' %}?v{{ settings.VERSION }}"></script>
{% endblock javascript %}
